// pages/user/addShopProduct.js
//获取应用实例
const app = getApp()
var util = require('../../utils/util.js')
var http = require('../../utils/server.js')
Page({

  data: {},

  onLoad: function(options) {
    var that = this;
    that.data.id = options.id;
    http.post({
      url: "Shop/getShopSoldOutProduct",
      shop_id: options.id
    }, function(data) {
      console.log('小店商品', data)
      that.setData({
        list: data
      });
    })
  },
  add: function(e) {
    var that = this;
    var id = this.data.id;
    var index = e.currentTarget.dataset.index;
    var product = that.data.list[index];
    http.post({
      url: "Shop/addProduct",
      shop_id: id,
      product_ids: [product.id]
    }, function(data) {
      console.log('筛选条件', data)
      product.add = 1;
      that.setData({
        list: that.data.list
      })
    })
  },
  allAdd: function() {
    var that = this
    var ids = []
    for (var i in that.data.list) {
      ids.push(that.data.list[i].id)
    }
    http.post({
      url: "Shop/addProduct",
      shop_id: that.data.id,
      product_ids: ids
    }, function(data) {
      var list = that.data.list
      for (var i in list) {
        list[i].add = 1
      }
      that.setData({
        list: list
      })
    })
  }
})